<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.9.0.min.js"></script>
<script type="text/javascript">
$(function(){
 var i = 2;
 $('#addTextImput').click(function(){
  if(i < 5) {
   $('#main').append('<div><input type="text" name="text" + i + ""/><span class="del-text">del</span></div>');
   i++;
  } else {
   alert("最多加4个");
  }
  
 });
 $('.del-text').live('click',function(){
 $(this).parent().remove();
 i--;
 });
});
</script>
</head>
<body>
<div id="main">
 <div><input type="text" name="text1"/></div>
</div>
<a id="addTextImput" href="#">添加文本框</a>
</body>
</html>